package com.hq.hotl.controller;

import com.hq.hotl.pojo.PageData;
import com.hq.hotl.service.HouseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

/*
* 管理房间的操作
* */
@Controller
public class HouseController {
    @Autowired
    private HouseService houseService;

    //分页查询全部的house信息
    @RequestMapping("allHouseyyl")
    public String allHouseyyl(Integer currentPage, Integer pageSize, ModelMap modelMap){
        //判断入参
        if (currentPage==null){
           currentPage=0;
        }
        if (pageSize==null){
            pageSize=0;
        }
        //调用HouseService层来实现方法
        PageData pageData = houseService.getAllHouse(currentPage, pageSize);
        //跳转页面，同时传递这些参数
        modelMap.put("pageData",pageData);
        return "list4";
    }

    //通过房间state信息查询得到分页的结果
    @RequestMapping("getHouseByState")
    public String getHouseByState(Integer currentPage,Integer pageSize,String state,ModelMap modelMap){
        //判断入参
        if (currentPage==null){
            currentPage=0;
        }
        if (pageSize==null){
            pageSize=0;
        }
        if (state==null){
            //没有传入state信息
            return "list4";
        }
        //调用Service层来执行方法
        PageData pageData = houseService.getHouseByState(currentPage, pageSize, state);
        modelMap.put("pageData",pageData);
        return "list4";
    }

    //分页来通过房间号获取到房间信息
    @RequestMapping("queryByRoomName")
    public String queryByRoomName(Integer currentPage,Integer pageSize,String name,ModelMap modelMap){
        //判断入参
        if (currentPage==null){
            currentPage=0;
        }
        if (pageSize==null){
            pageSize=0;
        }
        if (name==null){
            return "list4";
        }
        //调用service层的方法来执行
        PageData pageData = houseService.queryByRoomName(currentPage, pageSize, name);
        modelMap.put("pageData",pageData);
        return "list4";
    }

    //用房间类型来查询所有的房间信息
    @RequestMapping("queryByRoomType")
    public String queryByRoomType(Integer currentPage,Integer pageSize,String type,ModelMap modelMap){
        //判断入参
        if (currentPage==null){
            currentPage=0;
        }
        if (pageSize==null){
            pageSize=0;
        }
        if (type==null){
            return "list4";
        }
        //调用service层来执行方法
        PageData pageData = houseService.queryByRoomType(currentPage, pageSize, type);
        modelMap.put("pageData",pageData);
        return "list4";
    }
}
